# -*- mode: snippet -*-
# name: schema
# key: schema
# --
use Ecto.Schema
import Ecto.Changeset

@required_fields ~w(xxx)a
@non_cast_fields ~w(id inserted_at updated_at)a

schema "$1$0" do
  field(:xxx, :string)

  belongs_to(:xxx, Some.Module)
  has_many(:xxx, Some.Module)

  timestamps()
end

@doc false
def changeset($1, attrs) do
  attrs = attrs |> Tool.drop_empty()
  schema_fields = __schema__(:fields) -- @non_cast_fields

  $1
  |> cast(attrs, schema_fields)
  |> validate_required(@required_fields)
end
